﻿
@{
    Layout = null;
}

<link href="~/libs/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />

<div style="margin-top:20px;margin-left:20px;">
	<form class="layui-form">
		<div class="layui-form-item">
			<div class="layui-inline">
				<label>商品编码</label>
				<div class="layui-inline">
					<input id="productCode" style="width:200px;" class="layui-input" />
				</div>
			</div>
			<div class="layui-inline">
				<label>商品名称</label>
				<div class="layui-inline">
					<input id="productName" style="width:200px;" class="layui-input" />
				</div>
			</div>
			<div class="layui-inline">
				<div class="layui-inline">
					<button class="layui-btn" type="button" lay-on="test-page">+新增</button>
				</div>
			</div>
		</div>
	</form>
</div>
<div style="padding: 16px;">
	<table id="test" lay-filter="test" style="margin-top:10px;"></table>
</div>

<script type="text/html" id="toolDemo">
	<div class="layui-clear-space">
	  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	  <a class="layui-btn layui-btn-xs layui-bg-red" lay-event="delws">删除</a>
	</div>
</script>
<script src="~/libs/layui-v2.9.21/layui/layui.js"></script>
<script src="~/libs/jquery/jquery.js"></script>

<script>
		layui.use(['table', 'dropdown','form'], function(){
		  var table = layui.table;
		  var dropdown = layui.dropdown;
		  var form=layui.form;


		  //查询
		   $('#searchmaterial').on('click',function(){
				var productCode=$('#productCode').val();
				var productName=$('#productName').val();

				table.reload('test',{
					where:{
						productCode:productCode,
						productName:productName,
					}
				});
		   })

		   //显示
		  function getclientsdatas(){
			  // 创建渲染实例
		   table.render({
			elem: '#test',
			url: '/puff/GetTakenList', // 此处为静态模拟数据，实际使用时需换成真实接口
			page: true,
			limit:10,
			limits:[10,15,20],
			totalRow: true, // 开启合计行
			cols: [[
			  {field:'productCode',  title: '商品编码',align:'center'},
			  {field:'productName',  title: '商品名称',align:'center'},
			  {field:'productNum', title:'客户订单号',align:'center'},
			  {field:'result', title:'备注', align:'center'},
			  {field:'takenOffNum', title:'数量', align:'center'},
			  {field:'taskPeo', title:'任务接受人', align:'center'},
			  {field:'takenOffStatus', title:'货主', align:'center'},
			  {fixed: 'right', title:'操作', width: 134, minWidth: 125, templet: '#toolDemo'}
			]],
			done: function(){
			  var id = this.id;
			  },
		  })
		}

		getclientsdatas()

		//触发单元格工具事件
			table.on('tool(test)',function(obj){
				layEvent=obj.event;
				if(layEvent==='delws'){
					var data=obj.data;//获取当前行数据
					console.log(data)
					layer.confirm('确定删除该条信息吗？',function(index){
						$.ajax({
							url:'/Puff/DeleTakenoffs',
							type:'post',
							data:{
								id:data.id
							},
							dataType:'json',
							async:false,
							success:res=>{
								if(res>0){
									layer.msg('删除成功')
									getclientsdatas()
								}else{
									layer.msg('删除失败')
								}
							}
						})
					})
				}else if(layEvent==='edit'){
					var data=obj.data;//获取当前行数据
					layer.open({
					type: 2,
					title: "编辑下架",
					shade: [0.6],
					area: ['700px', '700px'],
					offset: ['0px', '200px'],
					shift: 2,
					content: ['/Puff/EditTakenView?id='+data.id, 'no'],
					end: function () {

					}
					});
				}
			})
		});

		//新增弹框
	layui.use(function(){
	  var $ = layui.$;
	  var layer = layui.layer;
	  var util = layui.util;
	  // 事件
	  util.on('lay-on', {
		'test-page': function(){
		  layer.open({
			type: 2,
			area: ['700px', '700px'],
			title:'新增',
			skin: 'layui-layer-rim', // 加上边框
			content: ['/puff/AddTakenView', 'no'] // 数组第二个成员设为 no 即屏蔽 iframe 滚动条
		  });
		},
	  })
	});
</script>

